package cn.tedu.ivoshw.user.controller;


import cn.tedu.ivoshw.base.response.JsonResult;
import cn.tedu.ivoshw.user.pojo.dto.UserLoginParam;
import cn.tedu.ivoshw.user.pojo.dto.UserQuery;
import cn.tedu.ivoshw.user.pojo.dto.UserSaveParam;
import cn.tedu.ivoshw.user.pojo.entity.User;
import cn.tedu.ivoshw.user.pojo.vo.UserVO;
import cn.tedu.ivoshw.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/user")
public class UserController {


    @Autowired
    UserService userService;


    @PostMapping("login")
    public JsonResult login(@RequestBody UserLoginParam userLoginParam){
        log.debug("用户登录：参数：{}",userLoginParam);
        UserVO userVO=userService.login(userLoginParam);
        return JsonResult.ok(userVO);

    }


    @GetMapping("select2")
    public JsonResult selectUser(UserQuery userQuery){
        log.debug("查询用户数据，参数：{}",userQuery);
        List<UserVO> list=userService.selectUser(userQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save2")
    public JsonResult saveUser(UserSaveParam userSaveParam){
        log.debug("保存用户数据，参数：{}",userSaveParam);
        userService.saveUser(userSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("update/status2/{userId}/{status}")
    public JsonResult updateUserStatus(@PathVariable  Long userId,@PathVariable String  status){
        log.debug("修改用户状态，参数{},{}",userId,status);
        userService.updateUserStatus(userId,status);

        return  JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteUser(@PathVariable Long id){
        log.debug("删除，参数{},{}",id);
        userService.delete(id);

        return  JsonResult.ok();

    }






}
